﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class TrangThaiDAO
    {
        public static List<TrangThaiDTO> LayDanhSach()
        {
            List<TrangThaiDTO> lstTrangThai = null;
            try
            {
                OleDbConnection cnn = BoKetNoiCSDL.KetNoi();
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM TRANG_THAI", cnn);
                try
                {
                    OleDbDataReader rd = cmd.ExecuteReader();
                    lstTrangThai = new List<TrangThaiDTO>();
                    while(rd.Read())
                    {
                        TrangThaiDTO trangThaiDto = new TrangThaiDTO();
                        trangThaiDto.MaTrangThai = (int)rd["MaTrangThai"];
                        trangThaiDto.TenTrangThai = (string)rd["TenTrangThai"];
                        lstTrangThai.Add(trangThaiDto);
                    }
                    cnn.Close();
                }
                catch (System.Exception ex)
                {
                	if(cnn.State == ConnectionState.Open)
                    {
                        cnn.Close();
                    }
                    throw ex;
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            return lstTrangThai;
        }
    }
}
